#include <iostream>

using namespace std;

static const int N = 4;
int flag[N]={0};
int v[N] = {1, 2, 3, 4};
int a[N];

void dfs(int depth)
{
	if (depth >= N)
	{
		for (int &i : a)
		{
			cout << i << " ";
		}
		cout << endl;
	}

	for (int i = 0; i < N; ++i)
	{
		if (0 == flag[i])
		{
			flag[i] = 1;
			a[depth] = v[i];
			dfs(depth+1);
			flag[i] = 0;
		}
	}
}

int main()
{

	dfs(0);
	return 0;
	//
}
